<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

//权限验证
if( Role::init() == false ){
	exit('没有权限');
}

$db = new DB();

$name = isset($_POST['name']) ? h($_POST['name']) : '';
$is_del = 1;
$created = time();
$updated = $created;

if( $name == '' ){
	echo '<script>alert("参数有误！");window.history.go(-1);</script>';
	exit;
}

//检测重复
$group_sql = 'select id from users_group where name="'.$name.'" and is_del=1 limit 1';
$group_rs = $db->query($group_sql)->getOne();
if( $group_rs['id'] > 0 ){
	echo '<script>alert("添加失败，用户 '.$name.' 已存在！");window.history.go(-1);</script>';
	exit;
}

$data=array('name'=>$name,
			'is_del'=>$is_del,
			'created'=>$created,
			'updated'=>$updated,
			);
$db->table('users_group')->insert($data)->run();

echo '<script>alert("添加成功！");window.location.href="/www/admin/role/position_lists.php";</script>';
exit;